package com.qf.smsplatform.util;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.constants.ReportStateConstants;
import com.qf.smsplatform.common.model.StandardReport;
import com.qf.smsplatform.common.model.StandardSubmit;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PushMessage2Queue {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 写日志消息
    public void sendLogMessage(StandardSubmit submit,String errorCode){
        // 发送失败
        submit.setReportState(ReportStateConstants.FAIL);
        // 失败原因
        submit.setErrorCode(errorCode);
        // 发送消息到SendLog队列
        rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_SMS_SEND_LOG,submit);
    }

    // 状态报告消息
    public void pushReportMessage(StandardSubmit submit,String errorCode){
        // 封装数据
        StandardReport report = new StandardReport();
        report.setClientID(submit.getClientID());
        report.setSrcID(submit.getSrcSequenceId());
        report.setErrorCode(errorCode);
        report.setMobile(submit.getDestMobile());
        report.setState(ReportStateConstants.FAIL);
        // 发送report对象到PushReport队列
        rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_PUSH_SMS_REPORT,report);
    }


}
